<?php

function oh_model_get_prefix($prefix = "") {
	$prefix = ($prefix == "") ? oh("config.model.default-prefix") : $prefix;
	$prefix = (strlen($prefix)>0) ? ("oh_".strtolower($prefix)."_") : ("oh_");
	return $prefix;
}

function oh_model_get_args($query,$data,$default_key="name",$replace_key=NULL) {
	$args = new stdClass();
	$temp = "";
	if (is_object($query)) return $query;
	if (is_array($query)) {
		$temp = $query;
	} else {
		parse_str($query,$temp);				
	}
	if ($replace_key) {
		$replace_key = oh_properties($replace_key);
	}
	
	$i = 0;
	foreach($temp as $k=>$v) {
		if (isset($replace_key[$k])) {
			$k = $replace_key[$k];
		}
		if (($v == "")&&($i == 0)) {
			$args->$default_key = $k;
		} else {
			$args->$k = $v;
		}
		$i++;
	}
	return $args;
}

function oh_model_get_insert($args,$type="object") {
	$fields = array();
	$values = array();				

	switch($type) {
		case "class":
			foreach($args as $key=>$value) {
				if (!in_array($key,oh("model")->excluded_fields_from_insert_class)) {
					$fields[] = $key;
					$values[] = "'".$value."'";	
				}
			}
		
		case "object":
			break;
			
		default:		
			break;
	}		

	return array(
		"fields" => implode(",",$fields),
		"values" => implode(",",$values)				
	);
}

function oh_model_get_prototype($record) {
	$record["a"] = 2;
	return $record;
}

?>
